; TV Noise for the Commodore 64 DTV
; Compiled with 64TASS

; by HMVDVA/HeMa!
; [c] 2010 HeMa!

.cpu 65dtv02


noisebank	= $4000
hop		= $4
zp_loadaddress  = $f0

*=$0801
.word ss,666
.null $9e,^start 

ss	.word 0

start						

			sei
		

			lda #$01	
			sta $D03F	;Enable extended features

			sac #$99	;enable burstmode and skipcycles
			lda #%00000011
			sac #$00	;
			cli


			lda #$55
			sta $D03C	;Enable Linear Mode
			lda #$5B
			sta $D011	
			lda #$18
			sta $D016
			lda #$08
			sta $D04C	;Stepping=8
			lda #$00
			sta $D049	;Screen location LOW
			sta $D04A	;Screen location MID
			ldx #$41
			stx $D04B	;Screen location HIGH

			LDY #$00	;Define first 16 palette colors
-			TYA	
			sta $D200,Y
			INY
			CPY #$10
			BNE	-

			lda #<noisebank
			ldy #>noisebank
			sta zp_loadaddress
			sty zp_loadaddress+1

			ldy #0
			sty $d020
			sty $d021

			ldx #4

bla

			sei
			sac #$dd
xx=*+1
			lda #hop
			sac #$00
			cli

-

			adc $d012 ; random
			eor $dc04 ; generator deluxe... ahum
			
			and #$0f
			sta (zp_loadaddress),y

			inc zp_loadaddress
			bne -

			lda zp_loadaddress+1
			cmp #$80
			beq reset_loadbank
			inc zp_loadaddress+1
			

			bra -

reset_loadbank
			lda #>noisebank
			sta zp_loadaddress+1
			inc xx

			dex
			
			bpl bla

loop

-
			lda	$d011
			bpl	-
-
			lda	$d011
			bmi	-

			lda $dc04	; random lolwtf
			sta $D049	;Screen location LOW
			lda $dc05	; random w00t!
			sta $D04A	;Screen location MID
			ldx #$41
			stx $D04B	;Screen location HIGH

			bra loop